package com.yida.gwj.scene.expend.controller;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yida.common.core.utils.poi.ExcelUtil;
import com.yida.common.core.web.controller.BaseController;
import com.yida.common.core.web.domain.AjaxResult;
import com.yida.common.core.web.page.TableDataInfo;
import com.yida.common.log.annotation.Log;
import com.yida.common.log.enums.BusinessType;
import com.yida.common.security.annotation.RequiresPermissions;
import com.yida.gwj.scene.expend.domain.GwjSceneExpendBusinessHouse;
import com.yida.gwj.scene.expend.domain.GwjSceneExpendBusinessHouseAndOwner;
import com.yida.gwj.scene.expend.domain.request.GwjSceneExpendHouseAndOwnerRequest;
import com.yida.gwj.scene.expend.service.IGwjSceneExpendBusinessHouseService;

/**
 * 业务房屋信息（旧支出模块）Controller
 * 
 * @author hmh
 * @date 2023-08-14
 */
@RestController
@RequestMapping("/house")
public class GwjSceneExpendBusinessHouseController extends BaseController {
    @Autowired
    private IGwjSceneExpendBusinessHouseService gwjSceneExpendBusinessHouseService;

    /**
     * 查询业务房屋信息（旧支出模块）列表
     */
    @RequiresPermissions("gwj:scene:expend:house:list")
    @GetMapping("/list")
    public TableDataInfo list(GwjSceneExpendBusinessHouse gwjSceneExpendBusinessHouse) {
        startPage();
        List<GwjSceneExpendBusinessHouse> list = gwjSceneExpendBusinessHouseService.selectGwjSceneExpendBusinessHouseList(gwjSceneExpendBusinessHouse);
        return getDataTable(list);
    }

    /**
     * 导出业务房屋信息（旧支出模块）列表
     */
    @RequiresPermissions("gwj:scene:expend:house:export")
    @Log(title = "业务房屋信息（旧支出模块）", businessType = BusinessType.EXPORT, systemName = "gwj")
    @PostMapping("/export")
    public void export(HttpServletResponse response, GwjSceneExpendBusinessHouse gwjSceneExpendBusinessHouse) {
        List<GwjSceneExpendBusinessHouse> list = gwjSceneExpendBusinessHouseService.selectGwjSceneExpendBusinessHouseList(gwjSceneExpendBusinessHouse);
        ExcelUtil<GwjSceneExpendBusinessHouse> util = new ExcelUtil<GwjSceneExpendBusinessHouse>(GwjSceneExpendBusinessHouse.class);
        util.exportExcel(response, list, "业务房屋信息（旧支出模块）数据");
    }

    /**
     * 获取业务房屋信息（旧支出模块）详细信息
     */
    @RequiresPermissions("gwj:scene:expend:house:query")
    @GetMapping(value = "/{bizHouseId}")
    public AjaxResult getInfo(@PathVariable("bizHouseId") Long bizHouseId) {
        return AjaxResult.success(gwjSceneExpendBusinessHouseService.selectGwjSceneExpendBusinessHouseByBizHouseId(bizHouseId));
    }

    /**
     * 新增业务房屋信息（旧支出模块）
     */
    @RequiresPermissions("gwj:scene:expend:house:add")
    @Log(title = "业务房屋信息（旧支出模块）", businessType = BusinessType.INSERT, systemName = "gwj")
    @PostMapping
    public AjaxResult add(@RequestBody GwjSceneExpendBusinessHouse gwjSceneExpendBusinessHouse) {
        return toAjax(gwjSceneExpendBusinessHouseService.insertGwjSceneExpendBusinessHouse(gwjSceneExpendBusinessHouse));
    }

    /**
     * 修改业务房屋信息（旧支出模块）
     */
    @RequiresPermissions("gwj:scene:expend:house:edit")
    @Log(title = "业务房屋信息（旧支出模块）", businessType = BusinessType.UPDATE, systemName = "gwj")
    @PutMapping
    public AjaxResult edit(@RequestBody GwjSceneExpendBusinessHouse gwjSceneExpendBusinessHouse) {
        return toAjax(gwjSceneExpendBusinessHouseService.updateGwjSceneExpendBusinessHouse(gwjSceneExpendBusinessHouse));
    }

    /**
     * 删除业务房屋信息（旧支出模块）
     */
    @RequiresPermissions("gwj:scene:expend:house:remove")
    @Log(title = "业务房屋信息（旧支出模块）", businessType = BusinessType.DELETE, systemName = "gwj")
    @DeleteMapping("/{bizHouseIds}")
    public AjaxResult remove(@PathVariable Long[] bizHouseIds) {
        return toAjax(gwjSceneExpendBusinessHouseService.deleteGwjSceneExpendBusinessHouseByBizHouseIds(bizHouseIds));
    }

    /**
     * 查询业务房屋信息（旧支出模块）列表
     */
    @RequiresPermissions("gwj:scene:expend:house:list")
    @GetMapping("/houseAndOwnerList")
    public TableDataInfo houseAndOwnerList(GwjSceneExpendBusinessHouse gwjSceneExpendBusinessHouse) {
        startPage();
        List<GwjSceneExpendBusinessHouseAndOwner> list = gwjSceneExpendBusinessHouseService.selectGwjSceneExpendBusinessHousesAndOwners(gwjSceneExpendBusinessHouse.getBizId(), gwjSceneExpendBusinessHouse.getAreaId(), "1");
        return getDataTable(list);
    }

    /**
     * 查询业务房屋类型
     */
    @GetMapping("/houseUseType")
    public AjaxResult houseUseType(Long bizId) {
        return AjaxResult.success(gwjSceneExpendBusinessHouseService.selectHouseUseType(bizId));
    }

    /**
     * 根据业务ID检测房屋业主信息是否空
     * 
     * @param bizId
     * @return
     */
    @GetMapping("/chekOwnerInfo")
    public AjaxResult checkOwnerInfo(Long bizId) {
        return toAjax(gwjSceneExpendBusinessHouseService.checkOwnerInfo(bizId));
    }

    /**
     * 修改房屋业主业务信息
     * 
     * @param gwjHouseAndOwnerRequest
     * @return
     */
    @Log(title = "公维金线下支出业务", businessType = BusinessType.UPDATE, systemName = "gwj")
    @RequiresPermissions("gwj:scene:expend:house:edit")
    @PutMapping("/updatBusinessHouseAndOwner")
    public AjaxResult updatBusinessHouseAndOwner(@RequestBody GwjSceneExpendHouseAndOwnerRequest gwjSceneExpendHouseAndOwnerRequest) {
        return toAjax(gwjSceneExpendBusinessHouseService.updatBusinessHouseAndOwnerInfoByBizId(gwjSceneExpendHouseAndOwnerRequest));
    }

    /**
     * 变更房屋选中状态
     * 
     * @param gwjSceneExpendBusinessHouse
     * @return
     */
    @Log(title = "公维金线下支出业务", businessType = BusinessType.UPDATE, systemName = "gwj")
    @RequiresPermissions("gwj:scene:expend:house:edit")
    @PutMapping("/changeHouseIfSelected")
    public AjaxResult changeHouseIfSelected(@RequestBody GwjSceneExpendBusinessHouse gwjSceneExpendBusinessHouse) {
        gwjSceneExpendBusinessHouseService.changeHouseIfSelected(gwjSceneExpendBusinessHouse.getBizId(), gwjSceneExpendBusinessHouse.getSelectFlag(), gwjSceneExpendBusinessHouse.getAreaId(), gwjSceneExpendBusinessHouse.getHouseCodes());
        return AjaxResult.success();
    }

    /**
     * 获取房屋统计数据
     * 
     * @param bizId
     * @return
     */
    @GetMapping("/countHoustData")
    public AjaxResult countHoustData(GwjSceneExpendBusinessHouse gwjSceneExpendBusinessHouse) {
        return AjaxResult.success(gwjSceneExpendBusinessHouseService.countHoustData(gwjSceneExpendBusinessHouse.getBizId(), gwjSceneExpendBusinessHouse.getAreaId(), "1"));
    }
}
